package mustry.alone.utils.convert;

import java.util.HashMap;
import java.util.Map;

import mustry.alone.utils.common.PublicTools;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONObject;

public class MapUtils {
	public static Map<String,Object> jsonString(String src){
		Map<String,Object> map = new HashMap<String, Object>();
		if(StringUtils.isEmpty(src)){
			return map;
		}
		JSONObject json = JSONObject.parseObject(src);
		for (Map.Entry<String,Object> entry : json.entrySet()) {
			if(StringUtils.isEmpty(entry.getValue().toString())){
				continue;
			}else{
				map.put(entry.getKey(),entry.getValue());
			}
		}
		return map;
	}
	
	public static Map<String,Object> urlString(String src){
		Map<String,Object> map = new HashMap<String, Object>();
		if(StringUtils.isEmpty(src)){
			return map;
		}
		String[] req = src.split("[?]");
		if(req.length < 2){
			return map;
		}
		String[] params = req[1].split("&");
		for(String param : params){
			 req = param.split("[=]",0);
			 map.put(req[0],PublicTools.decode(req[1], null));
		}
		System.out.println(map.toString());
		return map;
	}
}
